$(function () {
    layui.use(['table','util'], function(){
        var table = layui.table,util=layui.util;
        table.render({
            elem: '#admin'
            ,url:'../../tourist/getAllTourist',
            method:'POST'
            ,even:true
            ,cols: [[
                {field:'id', title: 'ID',width:80}
                ,{field:'tourist_name', title: '游戏名称'}
                ,{field:'city_name',  title: '游戏封面'}
                // ,{field:'longitude',  title: '经度'}
                ,{field:'opendate',  title: '开放日期'}
                ,{field:'opentime',  title: '开放时间'}
                ,{field:'description',  title: '描述'}
                // ,{field:'content',  title: '景点介绍'}
                ,{field:'address',  title: '地址'}
                // ,{field:'star',  title: '星级',width:100}
                ,{field:'createtime',title:'创建时间',templet: function(d) {return util.toDateString(d.createtime,"yyyy-MM-dd HH:mm:ss"); } }
                ,{ toolbar: '#barDemo',title:'操作'}
            ]]
            ,page: false,
        });
        table.on('tool(event)',function (obj) {
            if(obj.event === 'del'){
                layer.confirm('确定删除该景点吗,删除后不可撤回', function(index){
                    var data = obj.data;
                    $.ajax({
                        type: "POST",
                        url: "../../tourist/deleteTourist",
                        data: {
                            "tourist_id":data.id
                        },
                        dataType: "json",
                        success: function(data){
                            if(data.code==0){
                                obj.del();
                                layer.close(index);
                            }
                            layer.msg(data.msg);
                        }
                    });
                });
            }else if(obj.event=='detail'){
                //查看景点
                localStorage.setItem("data", JSON.stringify(obj.data));
                layer.open({
                    type: 2,
                    title: '景点详情',
                    content: 'detail.html',
                    maxmin: false,
                    area: ['800px', '600px'],
                    end: function() {
                    }
                });
            }else{
                //查看景点
                localStorage.setItem("data", JSON.stringify(obj.data));
                layer.open({
                    type: 2,
                    title: '编辑景点',
                    content: 'editTourist.html',
                    maxmin: false,
                    area: ['800px', '600px'],
                    end: function() {
                    }
                });
            }
        })
    });
})